from flask import Blueprint, session, request, make_response, render_template, redirect, url_for

blog = Blueprint('blog', __name__)


@blog.route('/')
def index():
    #设置过期时间
    session.permanent=True
    #设置
    session['name']=request.form['username']

    #获取
    username=session.get('name')
    #删除
    session.pop('username',None)
    session.clear()
    print(username)

    # 获取cookie
    name = request.cookies.get('name')
    resp = make_response('Please set your name using the /set_name route.')
    # 设置 cookie
    resp.set_cookie('name', 'John Doe')
    #return redirect(url_for('user/login')) #重定向到
    return render_template('blog.html')


@blog.before_request
def blog_before_request():
    print('this is blog_before_request')


@blog.after_request
def blog_after_request(response):
    print('this is blog_after_request')
    # 添加自定义响应头
    response.headers['BLOG-Custom-Header'] = 'My Custom Header Value'
    return response


if __name__ == '__main__':
    index()
